import requests
import pymysql

f=open("password.txt","r")
password=f.read()
f.close()
password=password.replace("\n","")
conn = pymysql.connect(host='localhost', user='root',
                       password=password, database='teamfight_wiki', port=3306)
cursor = conn.cursor()
base_url = "https://game.gtimg.cn/images/lol/act/img/tft/js/"
url = base_url + "hex.js"
f = open("海克斯.txt", "w",encoding="utf-8")
count = 0
response = requests.get(url)
data = response.json()
hax_type={"1":"一级强化符文","2":"二级强化符文","3":"三级强化符文"}
for i in data["data"]:
    i=data["data"][i]
    count += 1
    description = ""
    description += hax_type[i["type"]]+"^"+i["imgUrl"] + "$" + i["description"]
    description = description.replace("\n", " ")
    description = description.replace("\r", " ")
    if len(description) > 200:
        description = description[:200]
    print(count, i["name"], description)
    f.write(str(count) + "^" + i["name"] + "^" + description + '\n')
    sql = f"""INSERT INTO hex VALUES({count},"{i["name"]}","{description}");"""
    cursor.execute(sql)
conn.commit()
